package com.youi.web;



import com.alibaba.fastjson.JSONObject;
import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.common.SessionKey;
import com.youi.entity.Bankcode;
import com.youi.entity.Merchant;
import com.youi.entity.Sysuser;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.manage.HttpSessionManage;
import com.youi.model.BranchBankInfo;
import com.youi.model.ImgsObj;
import com.youi.service.*;
import com.youi.third.yibaopay.YibaopayUtil;
import com.youi.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;
import java.util.Map.Entry;

/**
* 商家信息控制层
* @author Administrator
*/
@Controller
public class MerchantController  extends HttpRequestManage{

		@Autowired
		private MerchantService merchantService;
		@Autowired
		private MerchantimgsService merchantimgsService;
		@Autowired
		private SysuserService sysuserService;
		@Autowired
		private MerchantbusinessService merchantbusinessService;
		@Autowired
		private MerchantsettlementService merchantsettlementService;
		@Autowired
		private ProvincecodeService provincecodeService;
		@Autowired
		private CitycodeService citycodeService;
		@Autowired
		private DistrictcodeService districtcodeService;
		@Autowired
		private BankcodeService bankcodeService;
		@Autowired
		private MerchantcertService merchantcertService;
		
		
		
		

		/**
		 * I-25
		 * 添加或编辑商家信息
		 * @param modelMap
		 * @param request
		 * @return
		 * @throws BusinessException
		 * @throws ParseException
		 */
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchant")
		public String addOrEditMerchant(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=optLong("id",request);
			Merchant merchant=null;
			if (id!=null) {
				merchant=merchantService.get(id);
			}else {
				merchant=new Merchant();
				merchant.setDelStatus(DelStatus.NODEL);
				merchant.setGmtCreated(new Date());
			}
			//商户名称
			String name=optString("name",request);
			if (name!=null){
				merchant.setName(name);
			}
			//商户简称
			String shortName=optString("shortName",request);
			if (shortName!=null){
				merchant.setShortName(shortName);
			}			
			Long merchantGroupId=optLong("merchantGroupId",request);
			if (merchantGroupId!=null){
				merchant.setMerchantGroupId(merchantGroupId);
			}
			Long merchantClassId=optLong("merchantClassId",request);
			if (merchantClassId!=null){
				merchant.setMerchantClassId(merchantClassId);
			}
			Integer status=optInteger("status",request);
			if (status!=null){				
				merchant.setStatus(status);
			}	
			Integer yipiaoStatus=optInteger("yipiaoStatus",request);
			if (yipiaoStatus!=null) {
				merchant.setYipiaoStatus(yipiaoStatus);
			}
			String merchantCode=optString("merchantCode",request);
			if (merchantCode!=null){
				merchant.setMerchantCode(merchantCode);
			}
			Integer nature=optInteger("nature",request);
			if (nature!=null){
				merchant.setNature(nature);
			}
			String project=optString("project",request);
			if (project!=null){
				merchant.setProject(project);
			}
			String ranges=optString("ranges",request);
			if (ranges!=null){
				merchant.setRanges(ranges);
			}
			String province=optString("province",request);
			if (province!=null){
				merchant.setProvince(province);
			}
			String city=optString("city",request);
			if (city!=null){
				merchant.setCity(city);
			}
			String district=optString("district",request);
			if (district!=null){
				merchant.setDistrict(district);
			}
			String contacts=optString("contacts",request);
			if (contacts!=null){
				merchant.setContacts(contacts);
			}
			String phone=optString("phone",request);
			if (phone!=null){
				merchant.setPhone(phone);
			}
			String email=optString("email",request);
			if (email!=null){
				merchant.setEmail(email);
			}
			String introduce=optString("introduce",request);
			if (introduce!=null){
				merchant.setIntroduce(introduce);
			}
			String address=optString("address",request);
			if (address!=null){
				merchant.setAddress(address);
			}
			String merchantPhone=optString("merchantPhone",request);
			if (merchantPhone!=null){
				merchant.setMerchantPhone(merchantPhone);
			}
			Integer isRecommend=optInteger("isRecommend",request);
			if (isRecommend!=null){
				merchant.setIsRecommend(isRecommend);
			}
			String brandName=optString("brandName",request);
			if (brandName!=null){
				merchant.setBrandName(brandName);
			}
			String brandIntroduce=optString("brandIntroduce",request);
			if (brandIntroduce!=null){
				merchant.setBrandIntroduce(brandIntroduce);
			}
			String account=optString("account",request);
			if (account!=null){
				merchant.setAccount(account);
			}
			String password=optString("password",request);
			if (password!=null){
				merchant.setPassword(MD5.getPwdMd5(password));
			}
			Integer accountNum=optInteger("accountNum",request);
			if (accountNum!=null){
				merchant.setAccountNum(accountNum);
			}
			Integer goodsNum=optInteger("goodsNum",request);
			if (goodsNum!=null){
				merchant.setGoodsNum(goodsNum);
			}
			Double commissionRatio=optDouble("commissionRatio",request);
			if (commissionRatio!=null){
				merchant.setCommissionRatio(commissionRatio);
			}
			String businessLicense=optString("businessLicense",request);
			if (businessLicense!=null){
				merchant.setBusinessLicense(businessLicense);
			}
			String gapMsg=optString("gapMsg",request);
			if (gapMsg!=null){
				merchant.setGapMsg(gapMsg);
			}
			String gspMsg=optString("gspMsg",request);
			if (gspMsg!=null){
				merchant.setGspMsg(gspMsg);
			}
			String idtscMsg=optString("idtscMsg",request);
			if (idtscMsg!=null){
				merchant.setIdtscMsg(idtscMsg);
			}
			String idisqcMsg=optString("idisqcMsg",request);
			if (idisqcMsg!=null){
				merchant.setIdisqcMsg(idisqcMsg);
			}
			Date gmtServiceEnd=optDate("gmtServiceEnd", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtServiceEnd!=null) {
				merchant.setGmtServiceEnd(gmtServiceEnd);
			}
			merchant.setGmtModify(new Date());
			merchantService.saveOrUpdate(merchant);
			//商家logo 
			String logo=optString("logo",request);
			if (logo!=null&&logo.length()>0) {
				ImgsObj merchanimgsObj=JsonUtil.fromJson(logo, ImgsObj.class);
				if (merchanimgsObj!=null&&merchanimgsObj.getImg()!=null) {
					merchantimgsService.addOrEditMerchantlogo(merchanimgsObj, merchant.getId());
				}
			}
			merchantService.addMerchantSysuer(merchant.getId(), account, password,merchant.getStatus());
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", merchant.getId());
			prams.put("role", 1);
			Sysuser merchantSysuser=sysuserService.getByParam(prams);
			if (merchantSysuser==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLOBJECT, "商家主账户不存在");
			}
			if (status==2||status==4) {				
				merchantSysuser.setOpenState(Common.TRUE);
				sysuserService.saveOrUpdate(merchantSysuser);
			}else {
				merchantSysuser.setOpenState(Common.FALSE);
				sysuserService.saveOrUpdate(merchantSysuser);
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchant.getId());
		}

		/**
		 *I-28
		 *  删除商家信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/delMerchantByIds")
		public String delMerchantByIds(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			String ids=getString("ids",request);
			List<Long> idsList=ObjectUtil.getIdListByIds(ids);
			if (idsList==null||idsList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "ids参数错误");
			}
			Map<String, Object> params=new HashMap<String, Object>();
			params.put(Common.DELSTATUS, DelStatus.NODEL);
			params.put(Common.ID, idsList);
			List<Merchant> merchantList= merchantService.getByParams(params);
			if (merchantList==null||merchantList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			for (Merchant merchant : merchantList) {				
				merchant.setStatus(3);
				Map<String, Object> prams=new HashMap<String, Object>();
				prams.put(Common.DELSTATUS, DelStatus.NODEL);
				prams.put("merchantId", merchant.getId());
				prams.put("role", 1);
				Sysuser merchantSysuser=sysuserService.getByParam(prams);
				if (merchantSysuser==null) {
					return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家主账户不存在");
				}
				merchantSysuser.setOpenState(Common.FALSE);
				sysuserService.saveOrUpdate(merchantSysuser);
			}
			merchantService.saveOrUpdateAll(merchantList);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		/**
		 * I-44
		 * 检测商家主账号是否重复
		 * @param modelMap
		 * @param request
		 * @return
		 * @throws BusinessException
		 */
		@ResponseBody
		@RequestMapping("sysUserGetInfo/checkMerchantAccount")
		public String checkMerchantAccount(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			String account=getString("account", request);
			Map<String, Object> params=new HashMap<String, Object>();
			params.put(Common.DELSTATUS, DelStatus.NODEL);
			params.put("account", account);
			Sysuser sysuser=sysuserService.getByParam(params);
			if (sysuser!=null) {
				return JsonUtil.toJson(CommonInfoUtil.OBJECTEXIST, "账号已存在");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "账号可注册");
		}
		
		/**
		 * I-26 
		 * 平台查询商家信息列表
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchant")
		public String getMerchant(ModelMap modelMap,HttpServletRequest request) throws BusinessException,ParseException{
			Integer pageIndex=optInteger("pageIndex",request,1);
			Integer pageNum=optInteger("pageNum",request,10);
			Integer status=optInteger(Common.STATUS, request);
			Integer yipiaoStatus=optInteger("yipiaoStatus", request);
			Long merchantGroupId=optLong("merchantGroupId", request);
			String des=optString("des",request,Common.DESC);
			String pms=optString("pms",request);
			Date start=optDate("start",request,"yyyy-MM-dd HH:mm:ss");
			Date end=optDate("end",request,"yyyy-MM-dd HH:mm:ss");
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			if (status!=null) {
				prams.put(Common.STATUS, status);
			}else {
				prams.put(Common.STATUS, Arrays.asList(1,2,4));
			}
			if (merchantGroupId!=null) {
				prams.put("merchantGroupId", merchantGroupId);
			}
			Map<String, Object> sortPram=new HashMap<String, Object>();
			sortPram.put(Common.ID,des);
			Map<String, Object> searchPram=null;
			if (pms!=null) {
				searchPram=new HashMap<String, Object>();
				searchPram.put("name", pms);
				searchPram.put("contacts", pms);
				searchPram.put("phone", pms);
			}
			Map<String, Object> startTime=null;
			if(start!=null){
				startTime=new HashMap<String, Object>();
				startTime.put(Common.GMTCREATED,start);
			}
			Map<String, Object> endTime=null;
			if(end!=null){
				endTime=new HashMap<String, Object>();
				endTime.put(Common.GMTCREATED,end);
			}
			List<Merchant> merchantList=merchantService.getByParamsList(prams, searchPram,sortPram,  (pageIndex-1)*pageNum, pageNum, startTime, endTime);
			if (merchantList==null||merchantList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			Integer pageCount=merchantService.getCountByParamss(prams, searchPram, startTime, endTime);
			modelMap.put(CommonInfoUtil.PAGECOUNT, Page.getCount(pageCount, pageNum));//pageCount  总页数
			modelMap.put(CommonInfoUtil.PAGEINDEX, pageIndex);			//pageIndex     查询页数
			modelMap.put(CommonInfoUtil.ALLCOUINT,pageCount);
			modelMap.put(CommonInfoUtil.DATA, merchantList);		//jsonObjectList json对象集合
			merchantService.getMerchantMsg(merchantList);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",modelMap);
		}

		/**
		 * I-27
		 * 查询商家信息详情
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantById")
		public String getMerchantById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Merchant merchant=merchantService.get(id);
			if (merchant==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			merchantService.getMerchantMsg(merchant);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchant);//jsonObject	json对象
		}

		/**
		 * I-53
		 * 重置商家主账户密码
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/resetMerchantpaaword")
		public String resetMerchantpaaword(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Sysuser sysuser=(Sysuser) HttpSessionManage.getAttribute(request, SessionKey.SYSUSER);
			if (sysuser.getType()!=0) {
				return JsonUtil.toJson(CommonInfoUtil.NOPERMISSIONS, "无权限操作"); 
			}
			Long id=getLong("id",request);
			String password=getString("password", request);
			Merchant merchant=merchantService.get(id);
			if (merchant==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家不存在");
			}
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", merchant.getId());
			prams.put("role", 1);
			Sysuser merchantSysuser=sysuserService.getByParam(prams);
			if (merchantSysuser==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家主账户不存在");
			}
			merchantSysuser.setPassword(MD5.getPwdMd5(password));
			merchant.setPassword(MD5.getPwdMd5(password));
			sysuserService.saveOrUpdate(merchantSysuser);
			merchantService.saveOrUpdate(merchant);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");//jsonObject	json对象
		}
		
		/**
		 * I-54
		 * 恢复商家信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/recoverMerchantById")
		public String recover(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id", request);
			Map<String, Object> params=new HashMap<String, Object>();
			params.put(Common.DELSTATUS, DelStatus.NODEL);
			params.put(Common.ID, id);
			Merchant merchant= merchantService.getByParam(params);
			if (merchant==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家不存在");
			}
			merchant.setStatus(2);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", merchant.getId());
			prams.put("role", 1);
			Sysuser merchantSysuser=sysuserService.getByParam(prams);
			if (merchantSysuser==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLOBJECT, "商家主账户不存在");
			}
			merchantSysuser.setOpenState(Common.TRUE);
			sysuserService.saveOrUpdate(merchantSysuser);
			merchantService.saveOrUpdate(merchant);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}
		
		/**
		 * I-29
		 * 查询所有商家信息
		 * @param modelMap
		 * @param session
		 * @return
		 */
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getAllMerchant")
		public String getAllMerchant(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put(Common.STATUS, Arrays.asList(2,4));
			List<Merchant> merchantList= merchantService.getByParams(prams);
			if (merchantList==null||merchantList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantList);//jsonObjectList	json对象集合
		}
		
		
		/**
		 * I-102
		 * 商家入驻易宝
		 * @param modelMap
		 * @param request
		 * @return
		 * @throws BusinessException
		 * @throws IOException 
		 */
		@ResponseBody
		@RequestMapping("sysUserGetInfo/enterMerchantToYibao")
		public String enterMerchantToYibao(ModelMap modelMap,HttpServletRequest request) throws BusinessException, IOException{
			Long id=getLong("id",request);
//			Merchant merchant=merchantService.get(id);
//			if (merchant==null) {
//				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家信息不存在");
//			}
//			Map<String, Object> prams=new HashMap<String, Object>();
//			prams.put(Common.DELSTATUS, DelStatus.NODEL);
//			prams.put("merchantId", merchant.getId());
//			Merchantbusiness merchantbusiness=merchantbusinessService.getByParam(prams);
//			if (merchantbusiness==null) {
//				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家营业信息不存在");
//			}
//			prams=new HashMap<String, Object>();
//			prams.put(Common.DELSTATUS, DelStatus.NODEL);
//			prams.put("merchantId", merchant.getId());
//			Merchantsettlement merchantsettlement=merchantsettlementService.getByParam(prams);
//			if (merchantsettlement==null) {
//				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家结算信息不存在");
//			}
//			prams=new HashMap<String, Object>();
//			prams.put(Common.DELSTATUS, DelStatus.NODEL);
//			prams.put("merchantId", merchant.getId());
//			Merchantcert merchantcert=merchantcertService.getByParam(prams);
//			if (merchantcert==null) {
//				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "商家证件信息不存在");
//			}
//			YopRequest yibaorequest = new YopRequest("OPR:"+"10033160799",PRIVATEKEY);
//			yibaorequest.addParam("parentMerchantNo","10033160799");
//			//商户全称
//			String merFullName=merchant.getName();
//			if (merFullName==null||merFullName.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户全称");
//			}
//			yibaorequest.addParam("merFullName",merFullName);
//
//			//商户简称
//			String merShortName=merchant.getShortName();
//			if (merShortName==null||merShortName.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户简称");
//			}
//			yibaorequest.addParam("merShortName",merShortName);
//
//			//证件号
//			String merCertNo=merchantbusiness.getScCode();
//			if (merCertNo==null||merCertNo.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少证件号");
//			}
//			yibaorequest.addParam("merCertNo",merCertNo);
//
//			//证件类型
//			yibaorequest.addParam("merCertType","UNI_CREDIT_CODE");
//
//			//法人姓名
//			String legalName=merchantbusiness.getContact();
//			if (legalName==null||legalName.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少法人姓名");
//			}
//			yibaorequest.addParam("legalName",legalName);
//
//			//法人身份证号
//			String legalIdCard=merchantbusiness.getContactIdCard();
//			if (legalIdCard==null||legalIdCard.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少法人身份证号");
//			}
//			yibaorequest.addParam("legalIdCard",legalIdCard);
//
//			//商户联系人姓名
//			String merContactName=merchant.getContacts();
//			if (merContactName==null||merContactName.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户联系人姓名");
//			}
//			yibaorequest.addParam("merContactName",merContactName);
//
//			//商户联系人手机号
//			String merContactPhone=merchant.getPhone();
//			if (merContactPhone==null||merContactPhone.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户联系人手机号");
//			}
//			yibaorequest.addParam("merContactPhone",merContactPhone);
//
//			//商户联系人邮箱
//			String merContactEmail=merchant.getEmail();
//			if (merContactEmail==null||merContactEmail.trim().length()==0) {
//
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户邮箱");
//			}
//			yibaorequest.addParam("merContactEmail",merContactEmail);
//
//			//商户省
//			String merProvince=merchant.getProvince();
//			if (merProvince==null||merProvince.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户省地址");
//			}
//			String provinceCode=provincecodeService.getProvincecodeByName(merProvince);
//			if (provinceCode==null||provinceCode.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有省地址编码");
//			}
//			yibaorequest.addParam("merProvince",provinceCode);
//
//			//商户市
//			String merCity=merchant.getCity();
//			if (merCity==null||merCity.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户市地址");
//			}
//			String cityCode=citycodeService.getCityCodeByCity(merCity);
//			if (cityCode==null||cityCode.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有市地址编码");
//			}
//			yibaorequest.addParam("merCity",cityCode);
//			String districtCode=districtcodeService.getDistrictcodeByCity(merCity);
//			if (districtCode==null||districtCode.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有区地址编码");
//			}
//			yibaorequest.addParam("merDistrict",districtCode);
//
//			//商户所在地址
//			String merAddress=merchant.getAddress();
//			if (merAddress==null||merAddress.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户所在地址");
//			}
//			yibaorequest.addParam("merAddress",merAddress);
//
//			//税务登记证编号
//			String taxRegistCert=merchantbusiness.getTaxCert();
//			if (taxRegistCert==null||taxRegistCert.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少税务登记证编号");
//			}
//			yibaorequest.addParam("taxRegistCert", taxRegistCert);
//			//开户许可证编号
//			String accountLicense=merchantbusiness.getAolNo();
//			if (accountLicense==null||accountLicense.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "开户许可证编号");
//			}
//			yibaorequest.addParam("accountLicense", accountLicense);
//			//组织机构代码证
////			request.addParam("orgCode", "91350206MA31G7XL1G");
//			//组织机构代理证有效期
////			request.addParam("orgCodeExpiry", "");
//			//组织机构代码证是否长期有效
////			request.addParam("isOrgCodeLong", "");
//			//结算银行账户
//			String cardNo=merchantsettlement.getBankcardNo();
//			if (cardNo==null||cardNo.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少结算银行账户卡号");
//			}
//			yibaorequest.addParam("cardNo",cardNo);
//			//开户银行编码
//			String headBank=merchantsettlement.getBank();
//			if (headBank==null||headBank.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少开户银行总行");
//			}
//			String headBankCode=merchantsettlement.getBankCode();
//			if (headBankCode==null||headBankCode.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有银行总行编码");
//			}
//			yibaorequest.addParam("headBankCode", headBankCode);
//			//开户银行支行编码
//			String bankBranch=merchantsettlement.getBranchCode();
//			if (bankBranch==null||bankBranch.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少开户支行");
//			}
//			yibaorequest.addParam("bankCode", bankBranch);
//			//开户省
//			String bankProvince=merchantsettlement.getProvince();
//			if (merProvince==null||merProvince.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少开户省地址");
//			}
//			String bankProvinceCode=provincecodeService.getProvincecodeByName(merProvince);
//			if (bankProvinceCode==null||bankProvinceCode.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有省地址编码");
//			}
//			yibaorequest.addParam("bankProvince", bankProvinceCode);
//
//			//开户市
//			String bankCity=merchantsettlement.getCity();
//			if (merCity==null||merCity.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "缺少商户市地址");
//			}
//			String bankCityCode=citycodeService.getCityCodeByCity(bankCity);
//			if (bankCityCode==null||bankCityCode.trim().length()==0) {
//				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有市地址编码");
//			}
//			yibaorequest.addParam("bankCity", bankCityCode);
//			//资质影印件
//			List<FileInfo> fileInfoList=ObjectUtil.getFileInfo(merchantcert);
//			String fileInfo=JsonUtil.toJson(fileInfoList);
//			yibaorequest.addParam("fileInfo",fileInfo);
//			//业务功能
//			yibaorequest.addParam("businessFunction","{\"SUBACCOUNT_IS_OPENED\": [\"YES\"]}");
//			//入网请求号
//			String requestNo=null;
//			if (merchant.getRequestNo()!=null) {
//				requestNo=merchant.getRequestNo();
//			}else {
//				requestNo=MD5.getPwdMd5("MYJ"+new Date().getTime()+SmsUtil.getRandom(4));
//			}
//			yibaorequest.addParam("requestNo", requestNo);
//			//商户回调地址
//			yibaorequest.addParam("notifyUrl", "https://mp.myjjk.com.cn/MeiYiJiaHealth/checkEnterMerchant");
//			YopResponse response = YopRsaClient.post("/rest/v1.0/sys/merchant/enterprisereginfoadd", yibaorequest);
//			JSONObject data=null;
//			if("FAILURE".equals(response.getState())){
//				if(response.getError() != null)
//				data=new JSONObject();
//				data.put("code", response.getError().getCode());
//				data.put("message", response.getError().getMessage());
//			}
//			if (response.getStringResult() != null) {
//				Object object=JsonUtil.fromJson(response.getStringResult().toString(), Object.class);
//				JSON json=(JSON) JSON.toJSON(object);
//				data=JSONObject.parseObject(json.toJSONString());
//				if (!data.getString("returnCode").equals("REG00000")) {
//					return JsonUtil.toJson(CommonInfoUtil.DATAERROR,data.getString("returnMsg"),data);
//				}
//				merchant.setMerchantNo(data.getString("merchantNo"));
//				merchant.setRequestNo(data.getString("requestNo"));
//				merchant.setYibaoStatus(1);
//				merchantService.saveOrUpdate(merchant);
//			}
			JSONObject data = merchantService.enterMerchantToYibao(id);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",data);//jsonObjectList	json对象集合
		}
		
		
		/**
		 * I-103 
		 * 查询开户行支行编码
		 * @param modelMap
		 * @param request
		 * @return
		 * @throws Exception 
		 */
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getBranch")
		public String getBranch(ModelMap modelMap,HttpServletRequest request) throws Exception{
			String headBankCode=getString("headBankCode", request);
			String province=getString("province", request);
			String city=getString("city", request);
			String branchCode=bankcodeService.getBankCodeByBank(headBankCode);
			if (branchCode==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "开户总行编码不存在");
			}
			String provinceCode=provincecodeService.getProvincecodeByName(province);
			if (provinceCode==null||provinceCode.trim().length()==0) {
				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有省地址编码");
			}
			String cityCode=citycodeService.getCityCodeByCity(city);
			if (cityCode==null||cityCode.trim().length()==0) {
				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "没有市地址编码");
			}
			List<BranchBankInfo> branchBankInfoList=null;
			Map<String, Object> param=YibaopayUtil.yibaoGetBranch(branchCode, provinceCode, cityCode);
			if (param!=null) {
				branchBankInfoList=new ArrayList<BranchBankInfo>();
				for (Entry<String, Object> entry : param.entrySet()) {
					String mapKey = entry.getKey();
				    String mapValue = (String) entry.getValue();
				    branchBankInfoList.add(new BranchBankInfo(mapKey, mapValue));
				}
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",branchBankInfoList);//jsonObjectList	json对象集合
		}
		
		/**
		 * I-104
		 * 查询开户银行总行信息
		 * @param modelMap
		 * @param request
		 * @return
		 * @throws Exception
		 */
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getBank")
		public String getBank(ModelMap modelMap,HttpServletRequest request) throws Exception{
			String des=optString("des",request,Common.DESC);
			String pms=optString("pms",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			Map<String, Object> sortPram=new HashMap<String, Object>();
			sortPram.put(Common.ID,des);
			Map<String, Object> searchPram=null;
			if (pms!=null) {
				searchPram=new HashMap<String, Object>();
				searchPram.put("name", pms);
			}
			List<Bankcode> bankcodeList=bankcodeService.getByParams(prams, searchPram, sortPram);
			if (bankcodeList==null||bankcodeList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",bankcodeList);
		}
		
}
